package com.hpp.utils;

/**
 * 日志格式化工具类
 * 
 * @author jiangwy
 * 
 */
public final class LogFormatUtils {

    private static final String PROCESS = "[PROCESS]";

    private static final String L = "[";

    private static final String R = "]";

    private static final String RL = "][";

    private static final String TIME_MS = "ms";

    private static final String LID = "LID=";

    private static final String ETM = "ETM=";

    private static final String MSG = "[MSG=";

    private static final String XR = "]";

    private static final String BLANK = "";

    private LogFormatUtils() {

    }

    /**
     * 格式化字符串
     * 
     * @param msg
     *            message
     * @return String
     */
    public static String logFormat(String msg) {
        String message = BLANK;
        if (msg != null) {
            message = msg;
        }

        MetaInfo meta = new MetaInfo(BLANK);

        StringBuffer buffer = new StringBuffer();
        buffer.append(PROCESS);
        buffer.append(L).append(LID).append(meta.getUuid()).append(RL);
        buffer.append(RL);
        long time = meta.getTime();
        buffer.append(ETM).append(time).append(TIME_MS);
        buffer.append(RL).append(meta.getMethod()).append(R);
        buffer.append(MSG).append(message).append(XR);
        return buffer.toString();
    }

    /**
     * init.
     * 
     * @param method
     *            httprequestURI
     */
    private static void init(String method) {
        MetaInfo info = new MetaInfo(method);
        // CacheService.putMetaInfo(info);
    }

    /**
     * getMetaInfo.
     * 
     * @return MetaInfo
     */
    private static MetaInfo getMetaInfo() {
        MetaInfo meta = null;// CacheService.getMetaInfo();
        // if (meta == null) {
        // init(BLANK);
        // meta = CacheService.getMetaInfo();
        // }
        return meta;
    }

}
